package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.PageRoleByNameVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.RoleIdVO;
import com.ssy.lingxi.member.merchant.model.vo.platform.request.PlatformRoleAuthMenuVO;
import com.ssy.lingxi.member.merchant.model.vo.platform.request.PlatformRoleAuthStatusVO;
import com.ssy.lingxi.member.merchant.model.vo.platform.request.PlatformRoleAuthVO;
import com.ssy.lingxi.member.merchant.model.vo.platform.response.PlatformRoleAuthButtonVO;
import com.ssy.lingxi.member.merchant.model.vo.platform.response.PlatformRoleAuthQueryVO;
import com.ssy.lingxi.member.merchant.model.vo.platform.response.PlatformRoleAuthTreeVO;
import com.ssy.lingxi.member.merchant.service.web.IPlatformRoleAuthService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 平台后台 - 设置会员角色权限相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-10-23
 */
@RestController
@RequestMapping("/member/platform/role")
public class PlatformRoleManageController {

    @Resource
    private IPlatformRoleAuthService platformRoleAuthService;

    /**
     * 分页查询角色列表
     * @param headers Http头部信息
     * @param pageVO  接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformRoleAuthQueryVO>> pageRoles(@RequestHeader HttpHeaders headers, @Valid PageRoleByNameVO pageVO) {
        return platformRoleAuthService.pageRoles(headers, pageVO);
    }

    /**
     * 查询角色权限，以树形菜单形式返回
     * @param headers Http头部信息
     * @param idVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/auth/tree", method = RequestMethod.GET)
    public Wrapper<PlatformRoleAuthTreeVO> treeRoleAuth(@RequestHeader HttpHeaders headers, @Valid RoleIdVO idVO) {
        return platformRoleAuthService.treeRoleAuth(headers, idVO);
    }

    /**
     * 根据左侧菜单Id，查询右侧按钮列表
     * @param headers Http头部信息
     * @param menuVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/auth/button", method = RequestMethod.GET)
    public Wrapper<PlatformRoleAuthButtonVO> getRoleAuthButtons(@RequestHeader HttpHeaders headers, @Valid PlatformRoleAuthMenuVO menuVO) {
        return platformRoleAuthService.getRoleAuthButtons(headers, menuVO);
    }

    /**
     * 修改角色权限
     * @param headers Http头部信息
     * @param roleAuthVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/auth/update", method = RequestMethod.POST)
    public Wrapper<Void> updateRoleMenus(@RequestHeader HttpHeaders headers, @RequestBody @Valid PlatformRoleAuthVO roleAuthVO) {
        return platformRoleAuthService.updateRoleMenus(headers, roleAuthVO);
    }

    /**
     * 修改角色状态
     * @param headers Http头部信息
     * @param statusVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/status/update", method = RequestMethod.POST)
    public Wrapper<Void> updateRoleStatus(@RequestHeader HttpHeaders headers, @RequestBody @Valid PlatformRoleAuthStatusVO statusVO) {
        return platformRoleAuthService.updateRoleStatus(headers, statusVO);
    }

    /**
     * 更新平台会员权限
     * @param headers Http头部信息
     * @param idVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/auth/sync", method = RequestMethod.POST)
    public Wrapper<Void> syncRoleAuth(@RequestHeader HttpHeaders headers, @RequestBody @Valid RoleIdVO idVO) {
        return platformRoleAuthService.syncRoleAuth(headers, idVO);
    }
}
